import java.lang.reflect.Field;
import java.util.Arrays;
class Student extends Person {
    public int score;
    private int grade;
}

class Person {
    public String name;
}
public class Main {
    public static void main(String[] args) {
        System.out.printf("Hello and welcome!");
        String a = "Hello";
        String b = "Hello2";
        Class cls = String.class;
        System.out.println(cls);
        System.out.println(a.getClass());
        Class cls1 = String.class;
        String s = "Hello";
        Class cls2 = s.getClass();
        boolean sameClass = cls1 == cls2; // true
        System.out.println(sameClass);
//        printClassInfo("".getClass());
//        printClassInfo(Runnable.class);
//        printClassInfo(java.time.Month.class);
//        printClassInfo(String[].class);
//        printClassInfo(int.class);
        Field [] fields = cls.getDeclaredFields();
        Field [] fields2 = cls.getFields();
        System.out.println(Arrays.toString(fields));
        System.out.println(Arrays.toString(fields2));
        Class stdClass = Student.class;
        try {
            // 获取public字段"score":
            System.out.println(stdClass.getField("score"));
            // 获取继承的public字段"name":
            System.out.println(stdClass.getField("name"));
            // 获取private字段"grade":
            System.out.println(stdClass.getDeclaredField("grade"));
        }catch (Exception e){

        }

    }
    static void printClassInfo(Class cls) {
        System.out.println("Class name: " + cls.getName());
        System.out.println("Simple name: " + cls.getSimpleName());
        if (cls.getPackage() != null) {
            System.out.println("Package name: " + cls.getPackage().getName());
        }
        System.out.println("is interface: " + cls.isInterface());
        System.out.println("is enum: " + cls.isEnum());
        System.out.println("is array: " + cls.isArray());
        System.out.println("is primitive: " + cls.isPrimitive());
    }
}